package com.wangjiyuan.giftshuo.ui.fragment.classify.shop.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.classifybean.shop.TreeBean;
import com.wangjiyuan.giftshuo.config.classify.ClassifyConstant;
import com.wangjiyuan.giftshuo.ui.activity.classify.shop_details.ShopDetLayoutActivity;
import com.wangjiyuan.giftshuo.utils.RecyclerViewAdapterHelper;

import java.util.List;

/**
 * 单品右边最里层的RecyclerView的item
 * Created by QXL on 2016/11/18.
 */

public class ShopContentItemRecAdapter extends RecyclerViewAdapterHelper<TreeBean.DataBean.CategoriesBean.SubcategoriesBean> {
    public ShopContentItemRecAdapter(Context context, List<TreeBean.DataBean.CategoriesBean.SubcategoriesBean> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_content, parent, false);
        return new ViewHolderContentItem(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        int widthPixels = mContext.getResources().getDisplayMetrics().widthPixels;
        int heightPixels = mContext.getResources().getDisplayMetrics().heightPixels;
        TreeBean.DataBean.CategoriesBean.SubcategoriesBean subcategoriesBean = mList.get(position);

        ((ViewHolderContentItem)holder).textView_item_content.setText(subcategoriesBean.getName());

        Glide.with(mContext).load(subcategoriesBean.getIconUrl())
                .placeholder(R.mipmap.white)
                .override(widthPixels/3,heightPixels/6)
                .into(((ViewHolderContentItem)holder).imageView_item_content);
    }


    class ViewHolderContentItem extends RecyclerView.ViewHolder implements View.OnClickListener{
        RelativeLayout relativeLayout_item_content;
        ImageView imageView_item_content;
        TextView textView_item_content;
        public ViewHolderContentItem(View itemView) {
            super(itemView);
            imageView_item_content= (ImageView) itemView.findViewById(R.id.imageView_item_content);
            textView_item_content= (TextView) itemView.findViewById(R.id.textView_item_content);

            relativeLayout_item_content= (RelativeLayout) itemView.findViewById(R.id.relativeLayout_item_content);
            relativeLayout_item_content.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.relativeLayout_item_content:
                    TreeBean.DataBean.CategoriesBean.SubcategoriesBean subcategoriesBean = mList.get(getAdapterPosition());
                    Intent intent=new Intent(mContext, ShopDetLayoutActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putSerializable(ClassifyConstant.SHOP_DET_LAYOUT_BEAN,subcategoriesBean);
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                    break;
            }
        }
    }
}
